{extend name="layout:base" /}
{block name="main_content"}
  <div class="page-content">
    <!--主题-->
    <?php if(!empty($current_page)): ?>
      <div class="page-header">
        <h1>
          您当前操作
          <small>
            <i class="ace-icon fa fa-angle-double-right"></i>
            {$current_page.title|default=''}
          </small>
        </h1>
      </div>
    <?php endif; ?>
    <div class="row">
      <div class="col-xs-12">
        <form class="form-horizontal adminform" id="model-form" method="post" action="">
          <div class="form-group">
            <label class="col-sm-2 control-label no-padding-right" for="form-field-1">
              上级菜单：
            </label>
            <div class="col-sm-10">
              <select name="parent_id"  class="col-sm-5" required>
                <option value="0">顶级菜单</option>
                {volist name="list" id="vo"}
                  <option value="{$vo.id}"  <?php if(isset($category["parent_id"]) && $category["parent_id"]==$vo["id"]){echo('selected="selected"');} ?>>{$vo.title}</option>
                {/volist}
              </select>
            </div>
          </div>
          <div class="space-4"></div>

          <div class="form-group">
            <label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 
              分类名：<span class="red">*</span>
            </label>
            <div class="col-sm-10">
              <input type="text" name="name" placeholder="请输入分类名" class="col-xs-10 col-sm-5" value="{$category.name|default=''}" required/>
            </div>
          </div>
          <div class="space-4"></div>

          <div class="form-group">
            <label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 
              分类标题：<span class="red">*</span>
            </label>
            <div class="col-sm-10">
              <input type="text" name="title" placeholder="请输入分类标题" class="col-xs-10 col-sm-5" value="{$category.title|default=''}" required/>
            </div>
          </div>
          <div class="space-4"></div>

          <div class="form-group">
            <label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 显示状态：  </label>
            <div class="col-sm-10" style="padding-top:5px;">
              <input name="status" value="1" class="ace ace-switch ace-switch-4 btn-flat" type="checkbox" <?php if(isset($category["status"]) && intval($category["status"])){echo('checked="checked"');} ?> />
              <span class="lbl"></span>
            </div>
          </div>
          <div class="space-4"></div>

          <div class="form-group">
            <label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 排序编号：  </label>
            <div class="col-sm-10">
              <input type="text" name="sort" maxlength="4" placeholder="编号越小越靠前" value="{$category.sort|default='0'}" class="col-xs-10 col-sm-5"/>
            </div>
          </div>
          <div class="space-4"></div>

          <div class="form-group">
            <label class="col-sm-2 control-label no-padding-right" for="form-field-1">
              SEO标题：
            </label>
            <div class="col-sm-10">
              <textarea name="seo_title" placeholder="请输入分类的SEO标题" class="col-xs-10 col-sm-5">{$category.seo_title|default=''}</textarea>
            </div>
          </div>
          <div class="space-4"></div>

          <div class="form-group">
            <label class="col-sm-2 control-label no-padding-right" for="form-field-1">
              SEO关键词：
            </label>
            <div class="col-sm-10">
              <textarea name="seo_keywords" placeholder="请输入分类的SEO标题" class="col-xs-10 col-sm-5">{$category.seo_keywords|default=''}</textarea>
            </div>
          </div>
          <div class="space-4"></div>

          <div class="form-group">
            <label class="col-sm-2 control-label no-padding-right" for="form-field-1">
              SEO描述：
            </label>
            <div class="col-sm-10">
              <textarea name="seo_title" placeholder="请输入分类的SEO描述" class="col-xs-10 col-sm-5">{$category.seo_description|default=''}</textarea>
            </div>
          </div>
          <div class="space-4"></div>

          <div class="form-group">
            <label class="col-sm-2 control-label no-padding-right" for="form-field-1">
              首页模板：
            </label>
            <div class="col-sm-10">
              <input type="text" name="template_index" maxlength="4" placeholder="" value="{$category.template_index|default=''}" class="col-xs-10 col-sm-5"/>
            </div>
          </div>
          <div class="space-4"></div>

          <div class="form-group">
            <label class="col-sm-2 control-label no-padding-right" for="form-field-1">
              列表页模板：
            </label>
            <div class="col-sm-10">
              <input type="text" name="template_list" maxlength="4" placeholder="" value="{$category.template_list|default=''}" class="col-xs-10 col-sm-5"/>
            </div>
          </div>
          <div class="space-4"></div>

          <div class="form-group">
            <label class="col-sm-2 control-label no-padding-right" for="form-field-1">
              详细页模板：
            </label>
            <div class="col-sm-10">
              <input type="text" name="template_show" maxlength="4" placeholder="" value="{$category.template_show|default=''}" class="col-xs-10 col-sm-5"/>
            </div>
          </div>
          <div class="space-4"></div>

          <div class="clearfix form-actions">
            <div class="col-md-offset-3 col-md-9">
              <?php if(isset($category['id'])): ?>
                <input type="hidden" name="id" value="{$category.id}">
              <?php endif; ?>
              <button class="btn btn-info" type="submit">
                <i class="ace-icon fa fa-check bigger-110"></i>
                保存
              </button>

              &nbsp; &nbsp; &nbsp;
              <button class="btn" type="reset">
                <i class="ace-icon fa fa-undo bigger-110"></i>
                重置
              </button>
            </div>
          </div>
        </form>
      </div>
    </div>
  </div>
{/block}
{block name="page_js"}
  <script src="{$site_root}/static/plugins/jquery-validate/jquery.validate.min.js"></script>
  <script type="text/javascript">
    $("form#model-form").validate({
      rules:{
        "title":{
          required: true,
          minlength: 2,
          maxlength: 50
        }, "name":{
          required: true,
          minlength: 2,
          maxlength: 50
        }, "sort":{
          min: 0,
          max: 9999
        }, "template_index":{
          maxlength: 100
        }, "template_list":{
          maxlength: 100
        }, "template_show":{
          maxlength: 100
        }
      },
      messages:{
        "title":{
          required: "分类标题不能为空",
          minlength: "分类标题不能少于1个字符",
          maxlength: "分类标题不能超过30个字符"
        }, "name":{
          required: "分类名不能为空",
          minlength: "分类名不能少于1个字符",
          maxlength: "分类名不能超过30个字符"
        }, "sort":{
          min: "排序编号不能小于0",
          max: "排序编号不能大于9999"
        }, "template_index":{
          maxlength: "首页模板不能超过100个字符"
        }, "template_list":{
          maxlength: "列表页模板不能超过100个字符"
        }, "template_show":{
          maxlength: "详细页模板不能超过100个字符"
        }
      },
      errorClass: "help-inline input-error",
      errorElement: "span",
      highlight:function(element, errorClass, validClass) {
        $(element).parents('.form-group').addClass('has-error');
      },
      unhighlight: function(element, errorClass, validClass) {
        $(element).parents('.form-group').removeClass('has-error');
      },
      submitHandler: function(form){
        var $form = $(form);
        $.ajax({
          url: $form.attr("action"),
          type: $form.attr("method"),
          dataType: "JSON",
          data: $form.serialize(),
          success: function(data){
            if(data.code){
              location.href = data["url"];
            }else{
              alert(data["msg"]);
            }
          }, error: function () {
            alert("数据执行错误！");
          }
        });
      }
    });
  </script>
{/block}